﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Ruminate.GUI.Framework;
using SharedLib.UI;
using Ruminate.GUI.Content;
using Microsoft.Xna.Framework;
using SharedLib.Network.Client;

namespace GameStateManagement
{
    class ConnexionScreen : GameScreen
    {
        public RuminateGUI gui;

        SpriteFont gameFont;

        public ConnexionScreen()
        {
            TransitionOnTime = TimeSpan.FromSeconds(1.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);

           
        }

        public override void LoadContent()
        {
            gui = new RuminateGUI(ScreenManager.Game);
            gui.SetTheme(new NewTheme(ScreenManager.Game.Content, gui));
            setupUI();
            base.LoadContent();
        }

        TextBox _txtPlayer;
        TextBox _txtServer;
        private void setupUI()
        {
            gui.AddElement(new Label(10, 10, "Player name :"));
            gui.AddElement(_txtPlayer=new TextBox(10, 40, 400, 40, 100));

            gui.AddElement(new Label(10, 100, "Server IP :"));
            gui.AddElement(_txtServer=new TextBox(10, 130, 400, 40, 100));

            _txtServer.Value = "192.168.2.2";
            _txtPlayer.Value = "guest"+DateTime.Now.Ticks;
            gui.AddElement(new Button(10, 200, "Connexion", delegate
            {
                String ip = _txtServer.Value ;
                String playerName = _txtPlayer.Value.Replace("\0","");
                LoadingScreen.Load(ScreenManager, true, this.ControllingPlayer,
                               new GameplayScreen(ip,playerName));
            }));
        }

        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            gui.Update();
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }

        public override void Draw(GameTime gameTime)
        {
            
            ScreenManager.SpriteBatch.Begin();



            ScreenManager.SpriteBatch.End();

            gui.Draw();
            base.Draw(gameTime);
        }
    }
}
